package com.tsinghuabigdata.edu.ddmath.adapter;

import android.content.Context;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.tsinghuabigdata.edu.ddmath.R;
import com.tsinghuabigdata.edu.ddmath.bean.OnlineTutoring;
import com.tsinghuabigdata.edu.ddmath.bean.SubmitQuestion;
import com.tsinghuabigdata.edu.ddmath.bean.SumbitedItem;
import com.tsinghuabigdata.edu.ddmath.view.MultiGridView;

import java.util.List;

/**
 * Created by Administrator on 2017/2/17.
 */

public class OnlineTutoringAdapter extends CommonAdapter<OnlineTutoring> {

    private TutorListener mTutorListener;
    public OnlineTutoringAdapter(Context context, List<OnlineTutoring> mDatas,TutorListener tutorListener) {
        super(context, mDatas);
        mTutorListener = tutorListener;
    }

    @Override
    protected int getLayoutId() {
        return R.layout.item_online_tutoring;
    }

    @Override
    protected void convert(ViewHolder helper, final int position, OnlineTutoring item) {
        helper.setText(R.id.tv_teacher_name, item.getName() + "老师");
        CheckBox cbAcceptTutor = helper.getView(R.id.cb_accept_tutor);
        LinearLayout llHasQueue = helper.getView(R.id.ll_has_queue);
        TextView tvNoQueue = helper.getView(R.id.tv_no_queue);
        RelativeLayout rlDisacceptTutoring = helper.getView(R.id.rl_disaccept_online_tutoring);
        TextView tvSelectTime = helper.getView(R.id.tv_select_time);
        Button btnSendTutor = helper.getView(R.id.btn_send_tutor);
        if (position % 3 == 0) {
            cbAcceptTutor.setChecked(true);
            cbAcceptTutor.setText("可接受在线辅导");
            tvSelectTime.setEnabled(true);
            btnSendTutor.setEnabled(true);
            llHasQueue.setVisibility(View.VISIBLE);
            tvNoQueue.setVisibility(View.INVISIBLE);
            rlDisacceptTutoring.setVisibility(View.INVISIBLE);
        } else if (position % 3 == 1) {
            cbAcceptTutor.setChecked(true);
            cbAcceptTutor.setText("可接受在线辅导");
            tvSelectTime.setEnabled(true);
            btnSendTutor.setEnabled(true);
            llHasQueue.setVisibility(View.INVISIBLE);
            tvNoQueue.setVisibility(View.VISIBLE);
            rlDisacceptTutoring.setVisibility(View.INVISIBLE);
        } else {
            cbAcceptTutor.setChecked(false);
            cbAcceptTutor.setText("不可接受在线辅导");
            tvSelectTime.setEnabled(false);
            btnSendTutor.setEnabled(false);
            llHasQueue.setVisibility(View.INVISIBLE);
            tvNoQueue.setVisibility(View.INVISIBLE);
            rlDisacceptTutoring.setVisibility(View.VISIBLE);
        }
        tvSelectTime.setOnClickListener( new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mTutorListener.selectTimeClick("1",position);
            }
        });
        btnSendTutor.setOnClickListener( new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mTutorListener.sendTutorClick("1",position);
            }
        });
    }

    public interface TutorListener {
        void selectTimeClick(String teacherId, int position);

        void sendTutorClick(String teacherId, int position);
    }


}
